package io.red;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.rmi.server.RMIServerSocketFactory;

/**
 *
 * @author Mariano Zapata
 */
public class ConfigurableServerSocketFactory implements RMIServerSocketFactory {

    private InetAddress ip;
    
    public ConfigurableServerSocketFactory(InetAddress ip) {
        this.ip= ip;
    }
    
    @Override
    public ServerSocket createServerSocket(int port) throws IOException {
        ServerSocket ss;
        if (ip == null)
            ss= new ServerSocket(port);
        else
        {
            ss= new ServerSocket();
            InetSocketAddress isa= new InetSocketAddress(ip, port);
            ss.bind(isa);
        }
        return ss;
    }
}
